Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Separate form and input filters #20

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

bakura10
Copy link
Contributor

This PR correctly uses field sets instead of forms. This allow much more easier extending as well as remove the need to rewrite the fields and validation rules.

Fieldsets also allow to enable relationships between entities.

One thing I'm not sure is the use of the ClassMethods hydrator by default. I think it should use DoctrineModule hydrator.

@mac_nibblet ping


// Add specific validation rules
$usernameValidators = $this->get('username')->getValidatorChain();
$usernameValidators->addValidator($usernameUniqueValidator);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bakura10 Why dont you just add inputs inside init() method? Then you'll have the updated ValidatorManager with UsernameUniqueValidator and EmailUniqueValidator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init() is not needed if you explicitly set dependencies like it is the case here. I don't know yet what to do.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But all filters and validators are dependencies. It makes no sense you explicitly set dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense. I'll change that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm in fact it's not so easy danizord, because the validator requires options… Not sure about how to do it. Plugin managers are always limited when it comes to option.. So I think the current solution is the best one for now :/.

@bakura10
Copy link
Contributor Author

bakura10 commented Jul 6, 2013

@danizord : The problem is that the input is already added here, so I cannot use the "->add" factory method. And validator chain does not contain factory. So I either: let it as it is, or create the validators in the input filter itself rather than in the factory.

@DASPRiD
Copy link
Member

DASPRiD commented Aug 3, 2013

I'd like to have this more separated – let's talk about this on IRC.

@bakura10
Copy link
Contributor Author

I've tried to do some work about it today but..... I started to lost myself :/. I think I'll need to restart this PR. Sorry for the delay :(.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling f5d0c1e on bakura10:fieldsets into 3ba9ac1 on Bacon:master.

@bakura10
Copy link
Contributor Author

bakura10 commented Sep 3, 2013

@DASPRiD : I'm done. Now needs review :).

One remark: I had too inject the NoObjectExsits validator insteaad of creating them inside the RegistrationInputFilter because it was a whole mess to mock (you cannot mock methods of existing object).

NOTE: considering the rename from password_hash to passwordHash for instance, this is because otherwise hydrator won't work (well, maybe ClassMethods because it has supports to convert underscore_separated to camelCase, but most other hydrator don't do that).

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 7a89a09 on bakura10:fieldsets into 3ba9ac1 on Bacon:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 7a89a09 on bakura10:fieldsets into 3ba9ac1 on Bacon:master.

* @param object $object
* @return object
*/
public function hydrate(array $data, $object)
{
if (isset($data['password'])) {
$data['password_hash'] = $data['password'];
$data['passwordHash'] = $data['password'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this one happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly for hydrators, as most hydrators often do "set" . $key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, I don't like all of those naming confusions. Sometimes underscore_separated, sometimes camelCase... But the problem is complex and if we want something coherent we really should establish a standard for common components, so that each component by default can assume something about how data is named :/.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We go with underscore_separated in all arrays so far, shouldn't be different here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be a problem for most hydrators that inflect the setter/getter based on the key. For instance DoctrineModule hydrator's assume that setter is "set" . ucfirst($key). So if we keep this underscore_separated people should define setFirst_Name method. I just went with the situation that will fit most situations without having to override each hydrator.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 1e9831f on bakura10:fieldsets into 3ba9ac1 on Bacon:master.

@dajaney
Copy link

dajaney commented Nov 13, 2013

In RegistrationServiceFactory.php there is a line:

$serviceLocator->get('RocketUser\Form\RegistrationForm'),

Change to?:

$serviceLocator->get('RocketUser\Form\User\RegistrationForm'),

In RegistrationServiceFactoryTest.php there is a line:

$locator->setService('RocketUser\Form\RegistrationForm', $registrationForm);

Change to?:

$locator->setService('RocketUser\Form\User\RegistrationForm', $registrationForm);

I have no GitHubFu, so no idea on how to make the changes here for you. :(

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling a0805a0 on bakura10:fieldsets into 3ba9ac1 on Bacon:master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants